{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "836ed7db",
   "metadata": {},
   "source": [
    "# Returning Multiple Values from an Electron\n",
    "\n",
    "In Python it's perfectly acceptable to return multiple values from a function. You can return multiple values from an electron and use them as input to another electron. To do so efficiently, use the following technique.\n",
    "\n",
    "In case (1), there are 2 new electrons created by covalent in order to be sent to different electrons. These inherit their dependencies from the parent electron including the executor, which means that will be run on a new executor instance -> as a new job altogether, just to retrieve the indexed result value. On the other hand in case (2) that \"parsing\" will actually be done on the next electron, which actually saves a lot of resources.\n",
    "\n",
    "\n",
    "Name\n",
    "Classification\n",
    "Intent/Goal\n",
    "AKA\n",
    "Motivation - problem and context, scenario\n",
    "Applicability - Context\n",
    "Structure - graphical, class and interaction diagram\n",
    "Participants - classes and objects used\n",
    "Collaboration - interactions of participants\n",
    "Consequences - results, side effects, tradeoffs\n",
    "Implementation\n",
    "Sample Coce\n",
    "Known uses\n",
    "Related patterns\n",
    "\n",
    "    Pattern Name and Classification: A descriptive and unique name that helps in identifying and referring to the pattern.\n",
    "    Intent: A description of the goal behind the pattern and the reason for using it.\n",
    "    Also Known As: Other names for the pattern.\n",
    "    Motivation (Forces): A scenario consisting of a problem and a context in which this pattern can be used.\n",
    "    Applicability: Situations in which this pattern is usable; the context for the pattern.\n",
    "    Structure: A graphical representation of the pattern. Class diagrams and Interaction diagrams may be used for this purpose.\n",
    "    Participants: A listing of the classes and objects used in the pattern and their roles in the design.\n",
    "    Collaboration: A description of how classes and objects used in the pattern interact with each other.\n",
    "    Consequences: A description of the results, side effects, and trade offs caused by using the pattern.\n",
    "    Implementation: A description of an implementation of the pattern; the solution part of the pattern.\n",
    "    Sample Code: An illustration of how the pattern can be used in a programming language.\n",
    "    Known Uses: Examples of real usages of the pattern.\n",
    "    Related Patterns: Other patterns that have some relationship with the pattern; discussion of the differences between the pattern and similar patterns.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1b8fc55a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import covalent as ct\n",
    "\n",
    "# Method (1):\n",
    "@ct.electron\n",
    "def task_1(x, y):\n",
    "    return x * 2, y ** 2\n",
    "\n",
    "@ct.electron\n",
    "def task_2(x, y):\n",
    "    return x ** 2, y ** 2\n",
    "\n",
    "@ct.lattice\n",
    "def workflow_1(a, b):\n",
    "    res_1, res_2 = task_1(a, b)\n",
    "    return task_2(res_1, res_2)\n",
    "\n",
    "\n",
    "# Method (2):\n",
    "@ct.electron\n",
    "def task_2_new(arr):\n",
    "    return arr[0] ** 2, arr[1] ** 2\n",
    "\n",
    "\n",
    "@ct.lattice\n",
    "def workflow_2(a, b):\n",
    "    res = task_1(a, b)\n",
    "    return task_2(res)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
